from tqdm import tqdm
#直接导入tqdm 会报错
import os
import numpy as np
from PIL import Image
import cv2
def main(root):
    """
    :param root: 文件夹根目录

    :return:
    """
    save_dir=os.path.join(root,'pad')
    if not os.path.exists(save_dir):
        os.makedirs(save_dir)
    image_ids = [imageids_filename[:-4] for imageids_filename in os.listdir(root) if
                 imageids_filename.endswith('.png')]

    for image_id in tqdm(image_ids):

        img_address = os.path.join(root, image_id + '.png')
        image = Image.open(img_address).convert("RGB")
        image_arr = np.array(image)
        copyMakeBorder_size = [2048, 2048]
        [h,w]=image_arr.shape[:2]
        pad_img = cv2.copyMakeBorder(image_arr, 0, copyMakeBorder_size[0] - h, 0,
                                          copyMakeBorder_size[1] - w,
                                          cv2.BORDER_CONSTANT, value=[0, 0, 0])
        pad_img=Image.fromarray(pad_img)
        pad_img.save(os.path.join(save_dir,image_id+'.png'))






if __name__ == '__main__':
    root=r'I:\wyx\data\Hik_zaishen\标注数据集\20-31.5\Water\mortar\image'
    main(root)